package de.karlNet.sambamanager.ldapController.commands;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Controller;

import de.karlNet.sambamanager.ldapModel.ITypeCheckerCallback;
import de.karlNet.sambamanager.ldapModel.LdapGroup;
import de.karlNet.sambamanager.ldapModel.LdapObject;

@Controller
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class RemoveAllSubGroupsFromGroup extends BaseCommand {
	@Autowired
	private RemoveGroupFromGroup removeGroupFromGroup;

	public void removeAllSubGroupsFromGroup(final LdapGroup parentGroup) {
		for (final LdapObject ldapObject : this.ldapMemberTree
				.getChildrenOfDN(parentGroup.getDn())) {
			ldapObject.isType(new ITypeCheckerCallback() {
				public void isGroup(LdapGroup group) {
					removeGroupFromGroup.removeGroupFromGroup(parentGroup,
							group);
				}
			});
		}
		this.resetTrees();
	}
}
